PWD=$(shell pwd)

CFLAGS+=-I${PWD}

MQTT_LIBPATH=mosquitto

LDFLAGS+=-lgpiod
LDFLAGS+=-lpthread
  

CFLAGS+=-Ihal -Ietc -Ilib
LIBS+=-L hal -lhal -Letc -letc -Llib -llib

LIBS+=-lmosquitto -lcjson -lpthread -lm 

SRCFILES = $(wildcard *.c)
IMAGE_NAME=$(shell basename ${PWD})


all: thrirdlibs entry modules binary

entry: 
	@echo " ";
	@echo " =========================================================";
	@echo " **        Compile \"${BINARIES}\" for ${ARCH}         ";
	@echo " =========================================================";

thrirdlibs:
	cd thirdlib && bash build.sh

modules:
	make -C hal 
	make -C lib
	make -C etc

binary:  ${SRCFILES}
	$(CC) $(CFLAGS) -o ${IMAGE_NAME} $^ ${LDFLAGS} ${LIBS}
	@echo " Compile over"


clean: 
	@make clean -C hal
	@make clean -C etc
	@make clean -C lib
	@rm -f *.o $(IMAGE_NAME) 
	@rm -rf *.gdb *.a *.so *.elf *-master *.zip


